package view;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ViewFactory implements and directs the flow of view invokation of requested views.
 *
 * @author Reynaldo Gonzales & Tyler Wood.
 * @version 1.0
 *
 */
public class ViewFactory {

    private static HttpServletResponse response;
    private static HttpServletRequest request;

    /**
     * ViewFactory() is the processor and director of user view requests and
     * also the responder to such as well.
     *
     * @param a HttpServletRequest request which holds the HTTP request
     * information of the requesting user.
     *
     * @param b HttpServletResponse response to the requesting user.
     *
     */
    public ViewFactory(HttpServletRequest req, HttpServletResponse res) {
        response = res;
        request = req;
    }

    /**
     * createView implements direction of which viw should be used based on a
     * valid view string name.
     *
     * @param a String viewType that corresponds to the name of an implemented
     * view.
     *
     * @throws generic IOException
     *
     * @return invokation of a view.
     *
     */
    public static View createView(String viewType) throws IOException {
        if (viewType.equals("UserPageHTML")) {
            return new UserPageHTML(request, response);
        }
        if (viewType.equals("UserPageXML")) {
            return new UserPageXML(request, response);
        }
        if (viewType.contains("LoginPageHTML")) {
            return new LoginPageHTML(request, response);
        }
        if (viewType.contains("LoginPageXML")) {
            return new LoginPageXML(request, response);
        }
        if (viewType.contains("UserPageContentDiv")) {
            return new UserPageContentDiv(request, response);
        }
        if (viewType.contains("UserPageFriendsDiv")) {
            return new UserPageFriendsDiv(request, response);
        }
        if(viewType.contains("UserPageDiscoverDiv")) {
            return new UserPageDiscoverDiv(request, response);
        }
        if(viewType.contains("UserPageLibraryXML")) {
            return new UserPageLibraryXML(request, response);
        }
        if(viewType.contains("UserPageFriendsXML")) {
            return new UserPageFriendsXML(request, response);
        }
        if(viewType.contains("UserPageBooksXML")) {
            return new UserPageBooksXML(request, response);
        }
        if(viewType.contains("UserPageDiscoverXML")) {
            return new UserPageDiscoverXML(request, response);
        }
        if (viewType.contains("RegisterPageHTML")) {
            return new RegisterPageHTML(request, response);
        } else {
            return new FrontPageHTML(request, response);
        }
    }

    /**
     * viewExists returns true providing a view name.
     *
     * @param a Sting view name.
     *
     * @return boolean indicating that the specific view exists.
     *
     */
    public static boolean viewExists(String view) {
        return true;
    }
}
